﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;

namespace NewGame
{

    public class MotionCamera : PerspectiveCamera
    {
        private int _nStep;

        private Vector3 _dPosition;
        private Vector3 _dTarget;
        private Vector3 _dUpVector;
        private Vector3 _targetPosition;
        private Vector3 _targetTarget;
        private Vector3 _targetUpVector;

        

        public MotionCamera()
        {
            _nStep = 0;
            _dPosition = new Vector3();
            _dTarget = new Vector3();
            _dUpVector = new Vector3();
            _targetPosition = new Vector3();
            _targetTarget = new Vector3();
            _targetUpVector = new Vector3();
        }

        public bool isSettled()
        {
            return _nStep == 0;
        }
        public void setNewInfor(Vector3 cameraPosition, Vector3 cameraTarget, Vector3 cameraUpVector,int step)
        {
            _targetPosition = cameraPosition;
            _targetTarget = cameraTarget;
            _targetUpVector = cameraUpVector;
            _nStep = step;
            _dPosition = (_targetPosition - _CameraPosition) / _nStep;
            _dTarget = (_targetTarget - _CameraTarget) / _nStep;
            _dUpVector = (_targetUpVector - _CameraUpVector) / _nStep;
        }
        public override void Update(GameTime gameTime)
        {
            if (_nStep > 1)
            {
                _CameraPosition += _dPosition;
                _CameraTarget += _dTarget;
                _CameraUpVector += _dUpVector;
                _nStep--;
            }
            else if (_nStep == 1)
            {
                _CameraPosition = _targetPosition;
                _CameraTarget = _targetTarget;
                _CameraUpVector = _targetUpVector;
                _nStep--;
            }

            base.Update(gameTime);

        }
    }
}
